<template>
  <div class="mobile-product-list common-mobile-view">
    <product-query />

    <el-empty v-if="productStore.productList.length === 0" description="暂无物品记录"/>

    <div v-else class="product-list">
      <product-card v-for="(item, index) in productStore.productList"
                    :key="index" :product-item="item"/>
    </div>

    <draggable-button @click="addClick"/>
  </div>
</template>

<script lang="ts" setup>
import DraggableButton from '@/components/Common/DraggableButton.vue'
import ProductQuery from '@/components/Product/ProductQuery.vue'
import ProductCard from '@/components/Product/ProductCard.vue'
import { useProductStore } from '@/store/product.ts'
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'

const productStore = useProductStore()
const router = useRouter()

onMounted(async () => {
  await productStore.queryProductList()
})

const addClick = () => {
  productStore.productApiType = 'ADD'
  productStore.currentProduct = productStore.getEmptyProduct()
  router.push({ name: 'ProductDetailId', params: { id: 0 } })
}
</script>

<style lang="scss">
.mobile-product-list {
  display: flex;
  flex-direction: column;
  gap: 10px;

  .product-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
}
</style>
